package org.melanesia.converters.jdbc;

import java.sql.CallableStatement;
import java.sql.Types;

import org.melanesia.converters.JavaToJdbcConverter;


/**
 * Default converter from Enum do JDBC type.
 * Converts enum to it's string representation using <code>name()</code> method, 
 * and defines it as a <code>Types#VARCHAR</code> JDBC type.
 *
 * @author mkielar
 */
public class EnumNameToJdbcConverter implements JavaToJdbcConverter {

	@Override
	public int getJdbcType() {
		return Types.VARCHAR;
	}

	@Override
	public Object convert(Object value, CallableStatement stmt, String parameterName) {
		return ((Enum<?>)value).name();
	}
};